package com.harvest.scientific.ladder.net

import BaseCanceledResponse
import BaseFailedResponse
import BaseResponse
import BaseSuccessResponse

/**
 * @Author: 633578
 * @Desc: 返回结果分类处理
 */
fun <T> BaseResponse<T>.parseData(callBack: HttpCallBack<T>.() -> Unit) {
    val mCallBack = HttpCallBack<T>().also(callBack)
    when (this) {
        is BaseCanceledResponse -> {}
        is BaseSuccessResponse -> mCallBack.onSuccess(this.firmSailingPublicHers)
        is BaseFailedResponse -> mCallBack.onFailed(this.furnishedLetterConnection, this.upsetTroublesomeSaturdaySecondExpense)
    }
    mCallBack.onComplete()
}

open class HttpCallBack<T> {
    var onSuccess: (data: T?) -> Unit = {}
    var onFailed: (code: Int?, msg: String?) -> Unit = { code, msg -> }
    var onComplete: () -> Unit = {}
}